﻿using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Net.Mail;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.UI.WebControls;
using OTS.BLL;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class DeliveryApplyWebService : System.Web.Services.WebService
{
    DeliveryDAO comm = new DeliveryDAO();
    DeliveryModel model = new DeliveryModel();
    EmailContent emailContent = new EmailContent();

    [WebMethod]
    public string HelloWorld()
    {
        return "Hello World";
    }

    [WebMethod]
    public string[] GetDivDll(string condiction)
    {
        string[] temp = new string[4];
        return temp;
    }

    [WebMethod]
    public int TradingQTYForShippmentUpdate(string rowID, string value)
    {
        return comm.TradingQTYForShippment(rowID, value);
    }

    [WebMethod]
    public int TradingDeliveryApply(string userCode, string coCode, string rowIDValue, string remark, string fileName)
    {
        model.UserCode = userCode;
        model.CoCode = coCode;
        model.rowIDValue = rowIDValue;
        model.remark = remark;
        model.fileName = fileName;

        int m = 0;
        m = comm.TradingDeliveryApply(model);   
        return m;
    }

    [WebMethod]
    public double GetDeliverySelectAmount(string contractNo, string soNo)
    {
        model.ContractNoMain = contractNo;
        model.SoNo = soNo;

        return comm.GetDeliverySelectAmount(model);
    }

    [WebMethod]
    public int TradingApproval(int n, string userCode, string coCode, string tradingIDs)
    {
        model.UserCode = userCode;
        model.CoCode = coCode;
        model.approvalFlag = n;
        model.M_SO_TradingID = "/" + tradingIDs;
        model.ContractNoMainSoNo = "/" + tradingIDs;
        model.rowIDValue = "/" + tradingIDs;

        int m = comm.Approval(model);
        return m;
    }
    [WebMethod]
    public int CreditCheckApproval(string falg, string cocode, string usercode, string contractno,
        string sono, string deliveryno, string customerno, string customeramount, string orederamount)
    {
        return DeliveryApprovalBuildBLL.CreditCheckApproval(falg, cocode, usercode, contractno,
            sono, deliveryno, customerno, customeramount, orederamount);
    }

    [WebMethod]
    public int ApprovalRemarkUpdate(string strID, string strValue, string userCode, string coCode,int n)
    {
        return comm.ApprovalRemarkUpdateDAO("/" + strID, strValue, userCode, coCode, n);
    }

    [WebMethod]
    public string[] ShowCreditCheck(string btnid, string creditcheckstatevalue,
        string customerno, string contractno, string sono, string deliveryno)
    {
        return DeliveryApprovalBuildBLL.ShowCreditCheck(btnid, creditcheckstatevalue, customerno, contractno, sono, deliveryno);
    }

    [WebMethod]
    public int saveFile(string path)
    {
        FileUpload aa = new FileUpload();
        aa.SaveAs(path);
        return 1;
    }

    //**************** Incasement ******************//
    [WebMethod]
    public int ChechFile(string fileName, string contractNo, string soNo)
    {
        //fileName = fileName.Substring(fileName.LastIndexOf('/') + 1, fileName.Length);
        string sql = string.Format(@"select count(1) from M_IncasementFiles where ContractNoMain='{0}' and SONo='{1}' and AttachedFileName='{2}'",
            contractNo, soNo, fileName);
        SqlHelp help = new SqlHelp();        
        return Convert.ToInt16(help.RunSqlReturn(sql));
    }
    [WebMethod]
    public int IncasementFileDelete(string filePath)
    {
        string path = Server.MapPath("~/" + filePath);

        System.IO.FileInfo fiL = new System.IO.FileInfo(path);

        if (fiL.Exists)
        {
            fiL.Delete();
            return 1;
        }
        return 0;
    }
    //**************** Incasement ******************//
}